﻿package org.xhs.report.common.utils
{
    import flash.events.*;
    import flash.system.*;
    import flash.text.*;
    import flash.utils.*;

    public class FPSMemCounter extends TextField
    {
        private var fontSize:Number;
        private var lastUpdate:Number;
        private var frameCount:Number;
        private var currentTime:Number;
        private static const UPDATE_INTERVAL:Number = 1000;

        public function FPSMemCounter(param1:Number = 16777215, param2:Number = 25) : void
        {
            this.textColor = param1;
            this.fontSize = 12;
            this.background = true;
            this.backgroundColor = 0;
            autoSize = TextFieldAutoSize.LEFT;
            selectable = false;
            mouseEnabled = false;
            addEventListener(Event.ADDED_TO_STAGE, this.setFPSUpdate);
            addEventListener(Event.REMOVED_FROM_STAGE, this.clearFPSUpdate);
            return;
        }// end function

        private function setFPSUpdate(event:Event) : void
        {
            addEventListener(Event.ENTER_FRAME, this.updateFPS);
            this.frameCount = 0;
            this.updateText(this.frameCount);
            this.lastUpdate = getTimer();
            return;
        }// end function

        private function clearFPSUpdate(event:Event) : void
        {
            removeEventListener(Event.ENTER_FRAME, this.updateFPS);
            return;
        }// end function

        private function updateFPS(event:Event) : void
        {
            this.currentTime = getTimer();
            var _loc_2:String = this;
            var _loc_3:* = this.frameCount + 1;
            _loc_2.frameCount = _loc_3;
            if (this.currentTime >= this.lastUpdate + UPDATE_INTERVAL)
            {
                this.lastUpdate = this.currentTime;
                this.updateText(this.frameCount);
                this.frameCount = 0;
            }
            return;
        }// end function

        private function updateText(param1:Number) : void
        {
            var _loc_2:* = Number(System.totalMemory / 1024 / 1024).toFixed(2) + "Mb";
            htmlText = "<span><strong>FPS : </strong>" + param1 + " fps<strong> Memory : </strong>" + _loc_2 + "</span>";
            return;
        }// end function

    }
}
